//
//  ZPMineChooseVC.m
//  ZPIOSEducation
//
//  Created by mini1 on 2017/1/17.
//  Copyright © 2017年 mini1. All rights reserved.
//

#import "ZPMineChooseVC.h"
#import "ZPMineChooseCell.h"
#import "ZPMineChooseDetailedCell.h"

static NSString  * const chooseCell = @"ZPMineChooseCell";
static NSString  * const chooseDetailedCell = @"ZPMineChooseDetailedCell";

@interface ZPMineChooseVC ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *contents;
}
@property (weak, nonatomic) IBOutlet UIButton *resetBtn;
@property (weak, nonatomic) IBOutlet UIButton *DetermineBtn;
@property (weak, nonatomic) IBOutlet UITableView *leadTableV;
@property (weak, nonatomic) IBOutlet UITableView *detailedTableV;
@property (strong, nonatomic) ZPMineChooseCell   *leadCell;
@property (strong, nonatomic) ZPMineChooseDetailedCell *detailedCell;

@end

@implementation ZPMineChooseVC
- (ZPMineChooseCell *)leadCell
{
    if (_leadCell == nil) {
        _leadCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPMineChooseCell class]) owner:self options:nil] lastObject];
    }
    return _leadCell;
}
- (ZPMineChooseDetailedCell *)detailedCell
{
    if (_detailedCell == nil) {
        _detailedCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPMineChooseDetailedCell class]) owner:self options:nil] lastObject];
    }
    return _detailedCell;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.leadTableV.delegate = self;
    self.leadTableV.dataSource = self;
   
    self.detailedTableV.delegate = self;
    self.detailedTableV.dataSource = self;
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.title = @"筛选";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhenpin_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
}
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 100) {
        return 10;
    }
    if (tableView.tag == 101)
    {
        return 24;
    } return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 100) {
        self.leadCell = [tableView dequeueReusableCellWithIdentifier:chooseCell];
        
//        UIView * view = [[UIView alloc] initWithFrame:self.leadCell.frame];
//        view.backgroundColor = white_color;
//        self.leadCell.selectedBackgroundView = view;
        
        NSArray *arr = @[@"教学点",@"老师"];
        self.leadCell.chooseLab.text = [NSString stringWithFormat:@"%@",[arr objectAtIndex:arc4random()%arr.count]];
        return self.leadCell;
    }
    if (tableView.tag == 101) {
        self.detailedCell = [tableView dequeueReusableCellWithIdentifier:chooseDetailedCell];
        self.detailedCell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (!contents.count) {
            self.detailedCell.chooseLab.text = @"";
        } else {
        self.detailedCell.chooseLab.text = [NSString stringWithFormat:@"%@",[contents objectAtIndex:arc4random()%contents.count]];
        }
        return self.detailedCell;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 100) {
        switch (indexPath.row) {
            case 0:{
                contents = @[@"五道口教学点",@"知春路教学点"];
                [self.detailedTableV reloadData];
            }
                break;
                
            case 1: {
                contents = @[@"李明",@"薛文慧",@"艾静"];
                [self.detailedTableV reloadData];
            }
                break;
            case 2:{
                contents = @[@"五道口教学点",@"知春路教学点"];
                [self.detailedTableV reloadData];
            }
                break;
                
            case 3: {
                contents = @[@"李明",@"薛文慧",@"艾静"];
                [self.detailedTableV reloadData];
            }
                break;
        }
    }
}


- (IBAction)resetBottonClick:(id)sender
{
    
}

- (IBAction)determineBottonClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
